import pandas as pd
from sklearn.metrics import cohen_kappa_score

def calculate_kappa(file_path):
    # 根据文件扩展名选择适当的读取方法
    if file_path.endswith('.csv'):
        # 读取CSV文件
        df = pd.read_csv(file_path)
    else:
        # 读取Excel文件
        df = pd.read_excel(file_path)
    
    # 提取分数
    human_scores = df['human_score'].values
    evolved_scores = df['model_score'].values
    
    # 计算带二次权重的Cohen's Kappa系数
    kappa = cohen_kappa_score(human_scores, evolved_scores, weights='quadratic')
    
    print(f"Cohen's Kappa系数: {kappa:.4f}")
    return kappa

if __name__ == "__main__":
    # 使用原始字符串(r前缀)或正确转义反斜杠
    excel_file_path = r"D:\AES code\EA\数据集2.xlsx"
    calculate_kappa(excel_file_path)
